Add type hints to all functions in metrics.py #446#447
Open
Sidhant185 wants to merge 2 commits intomllam:mainfrom
Open
Add type hints to all functions in metrics.py #446#447Sidhant185 wants to merge 2 commits intomllam:mainfrom
Sidhant185 wants to merge 2 commits intomllam:mainfrom
Conversation
21 tasks
sadamov
reviewed
Apr 1, 2026
Collaborator
sadamov
left a comment
There was a problem hiding this comment.
Overall looks good, just a few small things.
|
|
||
|
|
||
| def get_metric(metric_name): | ||
| def get_metric(metric_name: str): |
Collaborator
There was a problem hiding this comment.
get_metric is missing a return type. The PR description says "all functions" but this one's incomplete. Since it returns one of the metric callables, something like this works:
Suggested change
| def get_metric(metric_name: str): | |
| def get_metric(metric_name: str) -> "Callable[..., torch.Tensor]": |
You'd also need from collections.abc import Callable (or from typing import Callable) added to the imports.
| @@ -1,8 +1,11 @@ | |||
| # Standard library | |||
| from typing import Optional | |||
Collaborator
There was a problem hiding this comment.
Project requires Python >= 3.10, so Optional from typing is a legacy alias. torch.Tensor | None is preferred. If you update the usages, this import can be dropped entirely.
Suggested change
| from typing import Optional | |
| from collections.abc import Callable |
(if you also fix the get_metric return type above)
Collaborator
|
CHANGELOG entry is missing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Add
torch.Tensor,Optional[torch.Tensor]andbooltype hints to allfunction signatures and return types in
neural_lam/metrics.py.Functions updated:
get_metricmask_and_reduce_metricwmse,mse,wmae,mae,nll,crps_gaussNo logic changes were made — only type annotations were added.
Issue Link
closes #446
Type of change
Checklist before requesting a review
Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
metrics.pyChecklist for assignee